<template>
  <TableView
    ref="tableView"
    :table-attrs="{ api: getPage, descs: ['createTime'], payloadStyle: 'body', dicOptions: [] }"
    :form-path="formRoute"
    :search-model="searchForm"
    :delete-api="batchDelete"
    :toolbar-attrs="{ buttons: ['slot', 'del', 'create'] }">
    <template #toolbar-button>
      <ToolbarButton icon="el-icon-download" type="primary" label="导出" @click="exportExcel" />
    </template>
    <template #columns>
      <TableColumn label="项目名称" clickable prop="projectName" />
      <TableColumn label="项目编号" prop="projectNo" />
      <TableColumn label="负责人" prop="masterName" />
      <TableColumn label="经费 (万元)" prop="funds" />
      <TableColumn label="起止时间" prop="beginDateTime">
        <template #default="{ row }">{{ row.beginDateTime }}-{{ row.endDateTime }}</template>
      </TableColumn>
      <TableColumn label="项目类型" prop="projectType" dict-type="project_type" />
      <TableColumn label="项目管理专业机构" prop="manageOrg" />
      <TableColumn label="所属部门" prop="departmentName" />
      <TableColumn label="摘要" prop="summary" />
      <TableColumn label="课题设置" prop="topic" />
      <TableColumn label="项目研究阶段" prop="stage" />
      <TableColumn label="项目委托业务" prop="delegateName" />
    </template>
    <template #search-form>
      <FormInput v-model="searchForm.projectName" label="项目名称" prop="projectName" />
      <FormInput v-model="searchForm.projectNo" label="项目编号" prop="projectNo" />
      <FormSelect v-model="searchForm.projectType" label="项目类型" prop="projectType" dict-type="project_type" />
      <FormInput v-model="searchForm.masterName" label="负责人" prop="masterName" />
      <FormInput v-model="searchForm.funds" label="经费" prop="funds" />
      <FormInput v-model="searchForm.departmentName" label="所属部门名称" prop="departmentName" />
      <FormInput v-model="searchForm.manageOrg" label="项目管理专业机构" prop="manageOrg" />
      <FormInput v-model="searchForm.summary" label="摘要" prop="summary" />
      <FormInput v-model="searchForm.topic" label="课题" prop="topic" />
      <FormInput v-model="searchForm.stage" label="项目研究阶段" prop="stage" />
    </template>
  </TableView>
</template>

<script>
  import { getPage, batchDelete } from './api'
  import { services } from '@/config'

  export default {
    name: 'ProjectInformationView',
    data() {
      return {
        searchForm: {
          projectNo: null,
          masterName: null,
          funds: null,
          projectType: null,
          manageOrg: null,
          departmentName: null,
          summary: null,
          topic: null,
          stage: null,
          projectName: null
        }
      }
    },
    methods: {
      getPage,
      batchDelete,
      exportExcel() {
        this.$downBlobFile(`${services.personnelService}fyprojectinfo/export`, null, '项目信息.xlsx', 'post', this.$refs.tableView.getPageQuery())
      },
      formRoute(item) {
        return `/tech-project/project-manage/information/ProjectInformationForm/{id:-1}?tabTitle=${item ? item.projectName : '新建项目信息'}`
      }
    }
  }
</script>
